home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13061 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  38 lines

  1. Newsgroups: comp.lang.c,comp.unix.programmer
  2. Path: phcoms4.seri.philips.nl!panther!baynes
  3. From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes)
  4. Subject: Re: Q: '\n' character
  5. Sender: news@ukpsshp1.serigate.philips.nl (account for localnews)
  6. Message-ID: <DpBuF6.83C@ukpsshp1.serigate.philips.nl>
  7. Date: Thu, 4 Apr 1996 07:35:30 GMT
  8. References: <31616F63.481D@lava.weeg.uiowa.edu> <4jtddt$eu7@masala.cc.uh.edu>
  9. Organization: Philips Semiconductors, Southampton, UK
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Spasmo (cosc19z5@Bayou.UH.EDU) wrote:
  13. : Artur Wojdat (awojdat@lava.weeg.uiowa.edu) wrote:
  14. : : Hello everybody,
  15. : :     Is there a function or some sort of way that I could remove '\n' 
  16. : : charecter form the end of the string. I'm reading from two files, want to 
  17. : Dunno if there are any functions available, but what I always do
  18. : is just overwrite the '\n' with a '\0', which does the job nicely.
  19.  
  20. : For example, let's say that the string that holds the data is called
  21. : buf.  To get rid of the '\n' you'd merely do the following:
  22.  
  23. :     buf[strlen(buf) - 1] = '\0';
  24.  
  25. : And that takes care of that.
  26.  
  27. Thats the best way, but do check that the character you are about to overwrite
  28. is a newline. There are two occasions when fgets stops without reading a 
  29. newline, first if it has filled your buffer (because you have a very long line
  30. in the file), second if there is no newline at the end of the last line of the
  31. file.
  32.  
  33. --
  34. Stephen Baynes                              baynes@ukpsshp1.serigate.philips.nl
  35. Philips Semiconductors Ltd
  36. Southampton                                 My views are my own.
  37. United Kingdom
  38.